package org.openscheduler.common.util;

import java.util.Random;
import java.util.UUID;

public class KeyGenerator {
	
	public static String createRandomString(int length) {
		// ~,!,@,#,$,%,^,&,*,(,),-,_,=,+,\\,|,[,{,],},;,:,',\",<,>,/,?
		String chars[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(",");
		StringBuffer buffer = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			buffer.append(chars[random.nextInt(chars.length)]);
		}
		return buffer.toString();
	}
	
	public static String createRandomUUIDString(String str) {
		return UUID.randomUUID().toString();
	}
	
	public static String createUniqueString(String str) {
		String n1 = UUID.randomUUID().toString();
		String n2 = UUID.nameUUIDFromBytes(str.getBytes()).toString();
		return String.format("%s-%s", n2.substring(24), n1);
	}

}
